Use case: DCACHE maintenance in polling mode with error interrupt enabled

Sequence diagram

DCACHE maintenance in polling mode with error interrupt enabled.

  @startuml
  participant "User\nApplication" as UA order 1
  participant "DCACHE\nDriver" as DD order 2
  participant "DCACHE_IRQHandler" as IRQ order 3

  skinparam sequenceMessageAlign center

  == DCACHE Initialization ==

  group Option [USE_HAL_DCACHE_REGISTER_CALLBACKS]
  UA ->  DD : **HAL_DCACHE_RegisterCallback**(&hdcache, HAL_DCACHE_ERROR_CB_ID, USER_DCACHE_ErrorCallback)
  DD --> UA : return HAL_OK
  end
  UA -> DD : **HAL_DCACHE_Enable**
  DD --> UA : return HAL_OK
  UA -> DD : **__HAL_DCACHE_ENABLE_IT**
  rnote over DD
  Enable ERROR Interrupt
  endrnote
  |||
  UA-[#blue]>DD : **HAL_DCACHE_CleanByAddr**
  activate DD #blue
  note over DD : Check Busy flag : Flag = 0
  IRQ <[#orange]- : DCACHE Error interrupt
  IRQ -[#orange]> DD : **HAL_DCACHE_IRQHandler**
  activate DD #orange
  note over DD : Flag Error Interrupt = 1
  alt USE_HAL_DCACHE_REGISTER_CALLBACKS
  DD -[#orange]> UA : **USER_DCACHE_ErrorCallback**
  UA -[#orange]-> DD
  else USE OVERRIDDEN WEAK CALLBACKS
  DD -[#orange]> UA : **HAL_DCACHE_ErrorCallback**
  UA -[#orange]-> DD
  end
  deactivate DD
  DD -[#blue]-> UA : return HAL_OK
  deactivate DD
  |||
  rnote over UA
  The user can call __HAL_DCACHE_DISABLE_IT() to disable the Error Interrupt
  and call HAL_DCACHE_Disable() to stop the DCACHE or make an other action.
  endrnote
  @enduml

Code snippet

HAL1

HAL2

/* Enable error interrupt */
HAL_DCACHE_RegisterCallback(&hdcache, HAL_DCACHE_ERROR_CB_ID,
                            USER_DCACHE_ErrorCallback);
HAL_DCACHE_Enable(&hdcache);
__HAL_DCACHE_ENABLE_IT(&hdcache, DCACHE_IT_ERR);

/* Run a maintenance operation */
(void)HAL_DCACHE_CleanByAddr(&hdcache, (uint32_t *)buffer, buffer_size);

/* In IRQ handler */
void DCACHE_IRQHandler(void)
{
  HAL_DCACHE_IRQHandler(&hdcache);
}
/* Enable error interrupt */
HAL_DCACHE_RegisterErrorCallback(myDCACHE_ErrorCallback);
HAL_DCACHE_Start(&hdcache, HAL_DCACHE_IT_ERROR);

/* Run a maintenance operation */
(void)HAL_DCACHE_CleanByAddr(&hdcache, (uint32_t *)buffer, buffer_size);

/* In IRQ handler */
void DCACHE_IRQHandler(void)
{
  HAL_DCACHE_IRQHandler(&hdcache);
}

Key changes

  1. HAL2 uses HAL_DCACHE_RegisterErrorCallback() instead of registering by callback ID.

  2. HAL2 enables error interrupts via HAL_DCACHE_Start().

  3. The cache maintenance call remains HAL_DCACHE_CleanByAddr().